package com.example.xm503xk.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.xm503xk.R;

/**
 * Created by 肖阔 on 2017/5/23.
 */

public class registeredActivity extends Activity {
    private EditText register_username1,register_passwd,reregister_passwd,register_Rname,register_age;
    private Button register_submit,register_return;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.registered);
        register_username1=(EditText)findViewById(R.id.register_username1);
        register_passwd=(EditText)findViewById(R.id.register_passwd);
        reregister_passwd=(EditText)findViewById(R.id.reregister_passwd);
        register_Rname=(EditText)findViewById(R.id.register_Rname);
        register_age=(EditText)findViewById(R.id.register_age);
        register_submit=(Button)findViewById(R.id.register_submit);
        register_return=(Button)findViewById(R.id.register_return);

       //按钮监听
        register_submit.setOnClickListener(register_Lister);
        register_return.setOnClickListener(register_Lister);
   }


    View.OnClickListener register_Lister=new View.OnClickListener(){

       @Override
       public void onClick(View v) {
           switch (v.getId()){
               case R.id.register_return:
                   //返回登录   代码实现
                   R_login();
                   finish();
                   break;
               case R.id.register_submit:
                   //注册实现  代码
                   re_su();
                   break;
           }
       }
   };
  //返回登录
    public void R_login(){
        Intent intent_R_login=new Intent(registeredActivity.this,LoginActivity .class);
        startActivity (intent_R_login );
    }
    public  void re_su(){
        if(!TextUtils.isEmpty(register_username1.getText().toString())&&!TextUtils.isEmpty(register_passwd.getText().toString())
                &&!TextUtils.isEmpty(register_Rname.getText().toString())&&!TextUtils.isEmpty(register_age.getText().toString())){
            if (!register_passwd.getText().toString().equals((reregister_passwd.getText().toString()))) {
               Toast.makeText(registeredActivity.this, "两次密码输入不一致，请重新输入！", Toast.LENGTH_LONG).show();
                ((EditText) findViewById(R.id.register_passwd)).setText("");//清空密码
                ((EditText) findViewById(R.id.reregister_passwd)).setText("");//清空确认密码
                ((EditText) findViewById(R.id.register_passwd)).requestFocus();//让密码框获得焦点
            }
               else {
                Intent intent_R_login = new Intent(registeredActivity.this,LoginActivity.class);
                  Bundle bundle=new Bundle();
     //           bundle.putCharSequence("user", (CharSequence) register_Rname); //保存用户名
//                  bundle.putCharSequence("pass", (CharSequence) register_passwd); //保存密码
 //                 bundle.putCharSequence("number", (CharSequence) register_age); //手机
                intent_R_login.putExtras(bundle);
                Toast.makeText(registeredActivity.this, "正在跳转登录界面，请稍等！", Toast.LENGTH_LONG).show();
                startActivity(intent_R_login);
            }
        }
        else
            Toast.makeText(registeredActivity.this,"请将注册信息输入完整！",Toast.LENGTH_LONG).show();

    }

}
